package com.software.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;

/**
 * @BelongsProject: Second-hand-trading-platform
 * @BelongsPackage: com.software.utils
 * @Author: wyj
 * @CreateTime: 2024-02-27  15:44
 * @Description:生成MD5哈希值并将其编码为Base64字符串
 * @Version: 1.0
 */
public class Md5Util {
    public static String encode(String code ){

        MessageDigest messageDigest = null;
        try {
            messageDigest = MessageDigest.getInstance("md5");
            return Base64.getEncoder().encodeToString(messageDigest.digest(code.getBytes()));

        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }

        return  null ;
    }

    public static void main(String[] args) {
        System.out.println(encode("123456"));
    }
}
